package com.qf.controller.advice;

import com.qf.dto.R;
import com.qf.exceptions.MyBaseException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/*
杨威
2021/10/25
21:19
*/
@ControllerAdvice//增强器
@RestController
public class MyExceptionAdvice {
//    @ResponseBody//返回json
    @ExceptionHandler(MyBaseException.class)
    public R processMyBaseException(MyBaseException exception){
        int code=exception.getCode();
        String msg=exception.getMessage();
        return R.setError(code,msg,null);
    }
}
